//
//  NewKnowledgeViewController.m
//  NewPro
//
//  Created by RYX on 2019/4/28.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "NewKnowledgeViewController.h"
#import "JCViewController.h"
#import "ZYViewController.h"
#import "SCViewController.h"
#import "SMPagerTabView.h"
#import "KWebViewController.h"

@interface NewKnowledgeViewController ()<SMPagerTabViewDelegate,JCViewControllerDelegate,ZYViewControllerDelegate,SCViewControllerDelegate>

@property (nonatomic, strong) NSMutableArray *vcArr;
@property (nonatomic, strong) SMPagerTabView *segmentView;

@end

@implementation NewKnowledgeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNavBarWithTitle:@"知识讲堂"];
    
    [self setUI];
}

- (void)setUI{
    
    _vcArr = [NSMutableArray array];
    
    JCViewController *vc1 = [[JCViewController alloc]initWithNibName:nil bundle:nil];
    vc1.delegate = self;
    vc1.title = @"基础";
    
    ZYViewController *vc2 = [[ZYViewController alloc]initWithNibName:nil bundle:nil];
    vc2.delegate = self;
    vc2.title = @"专业";
    
    SCViewController *vc3 = [[SCViewController alloc]initWithNibName:nil bundle:nil];
    vc3.delegate = self;
    vc3.title = @"实操";
    
    [_vcArr addObject:vc1];
    [_vcArr addObject:vc2];
    [_vcArr addObject:vc3];
    
    self.segmentView.delegate = self;
    //可自定义背景色和tab button的文字颜色等
    //开始构建UI
    [_segmentView buildUI];
    [_segmentView selectTabWithIndex:0 animate:YES];
}

- (void)setIndex{
    
    [_segmentView selectTabWithIndex:1 animate:NO];
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - DBPagerTabView Delegate
- (NSUInteger)numberOfPagers:(SMPagerTabView *)view {
    return [_vcArr count];
}
- (UIViewController *)pagerViewOfPagers:(SMPagerTabView *)view indexOfPagers:(NSUInteger)number {
    return _vcArr[number];
}

- (void)whenSelectOnPager:(NSUInteger)number {
    NSLog(@"页面 %lu",(unsigned long)number);
}

#pragma mark - setter/getter
- (SMPagerTabView *)segmentView {
    if (!_segmentView) {
        self.segmentView = [[SMPagerTabView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - (iPhoneX_Top))];
        [self.view addSubview:_segmentView];
    }
    return _segmentView;
}

- (void)onCell{
    
    KWebViewController *VC = [[KWebViewController alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
}
@end
